package com.hpin.mlxteacher.adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hpin.mlxteacher.R;
import com.hpin.mlxteacher.child.ChildDetailActivity;
import com.hpin.mlxteacher.child.WatchDetailActivity;

/**
 * Created by Aaron on 15/7/29.
 */
public class ChildAdapter extends BaseAdapter {

    private Context ctx;

    public ChildAdapter(Context ctx) {
        this.ctx = ctx;
    }

    @Override
    public int getCount() {
        return 12;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder=null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_child, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_headpic = (ImageView) convertView.findViewById(R.id.iv_headpic);

            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_distance = (TextView) convertView.findViewById(R.id.tv_distance);
            viewHolder.tv_introduce = (TextView) convertView.findViewById(R.id.tv_introduce);

            viewHolder.tv_baby_detail = (TextView) convertView.findViewById(R.id.tv_baby_detail);
            viewHolder.tv_watch_detail = (TextView) convertView.findViewById(R.id.tv_watch_detail);
            viewHolder.tv_call_watch = (TextView) convertView.findViewById(R.id.tv_call_watch);

            convertView.setTag(viewHolder);

        }else{
            viewHolder=(ViewHolder) convertView.getTag();
        }

        viewHolder.tv_baby_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //详情
                Intent intent = new Intent(ctx, ChildDetailActivity.class);
                ctx.startActivity(intent);
            }
        });

        viewHolder.tv_watch_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //手表详情
                Intent intent = new Intent(ctx, WatchDetailActivity.class);
                ctx.startActivity(intent);
            }
        });

        viewHolder.tv_call_watch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(ctx).setMessage("15311280989").setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).setPositiveButton("呼叫", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        //拨打电话
                        Intent intent=new Intent("android.intent.action.CALL", Uri.parse("tel:" + "15311280989"));
                        ctx.startActivity(intent);


                    }
                }).show();
            }
        });

        return convertView;
    }

    private class ViewHolder {
        private ImageView iv_headpic;
        private TextView tv_name;
        private TextView tv_distance;
        private TextView tv_introduce;

        private TextView tv_baby_detail;
        private TextView tv_watch_detail;
        private TextView tv_call_watch;

    }
}
